package www.openteam.com.model.business.other;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.PackTypeInfo;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * 搜索包装类型model
 * Created by kylin on 2016/11/30.
 */

public class SearchPackTypeInfoModel extends BaseModel {
    private boolean isQuery = false;

    public boolean queryPackTypeInfo(String name, int pageSize, final SearchPackTypeInfoOnListener searchPackTypeInfoOnListener) {

        httpApiService.queryPackTypeInfo(name, pageSize)
                .compose(new CommonTransformer<PackTypeInfo>())
                .subscribe(new CommonSubscriber<PackTypeInfo>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(PackTypeInfo packTypeInfo) {
                        isQuery = true;
                        searchPackTypeInfoOnListener.queryPTISuccess(packTypeInfo);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQuery = false;
                        searchPackTypeInfoOnListener.queryPTIFail(e);
                    }
                });

        return isQuery;

    }


    public interface SearchPackTypeInfoOnListener {
        void queryPTISuccess(PackTypeInfo packTypeInfo);

        void queryPTIFail(Throwable throwable);
    }
}
